package cn.da.shuai.cool.system.api.controller;

import cn.da.shuai.cool.common.entity.R;
import cn.da.shuai.cool.system.model.entity.notice.CoolNotice;
import cn.da.shuai.cool.system.service.service.ICoolNoticeService;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公告 信息操作处理
 */
@RestController
@RequestMapping("/system/notice")
@Tag(name = "通知公告")
public class CoolNoticeController {

    @Autowired
    private ICoolNoticeService noticeService;

    @PostMapping("/list")
    @Operation(summary = "获取通知公告列表")
    public R<List<CoolNotice>> list(@RequestBody CoolNotice notice) {
        return R.ok(noticeService.getList(notice));
    }

    @PostMapping("/page")
    @Operation(summary = "获取通知公告分页列表")
    public R<IPage<CoolNotice>> page(@RequestBody CoolNotice notice) {
        return R.ok(noticeService.getPage(notice));
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据通知公告编号获取详细信息")
    public R<CoolNotice> getInfo(@PathVariable Long id) {
        return R.ok(noticeService.getById(id));
    }

    @PostMapping
    @Operation(summary = "新增通知公告")
    public R<Void> add(@RequestBody CoolNotice notice) {
        noticeService.save(notice);
        return R.ok();
    }

    @PutMapping
    @Operation(summary = "修改通知公告")
    public R<Void> edit(@RequestBody CoolNotice notice) {
        noticeService.saveOrUpdate(notice);
        return R.ok();
    }

    @DeleteMapping("/{noticeIds}")
    @Operation(summary = "删除通知公告")
    public R<Void> remove(@PathVariable List<Long> noticeIds) {
        if (CollectionUtil.isEmpty(noticeIds)) {
            return R.ok();
        }
        noticeService.removeBatchByIds(noticeIds);
        return R.ok();
    }
}